package servlet;

import bean.Thump;
import dao.ImpI.SelectNumDaoImpI;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(urlPatterns = "/select")
public class Select extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        SelectNumDaoImpI selectNumDaoImpI = new SelectNumDaoImpI();
        Thump thump = selectNumDaoImpI.SelNum();
        resp.setContentType("text/html;utf-8");
        JSONObject jsonObject = JSONObject.fromObject(thump);
        System.out.println("json数据:"+jsonObject);
        PrintWriter writer = resp.getWriter();
        writer.print(jsonObject);
    }
}
